package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdAcousticsIsotropicSolidMaterialBo;
import com.comac.ins.isfd.domain.bo.query.IsfdAcousticsIsotropicSolidMaterialQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdAcousticsIsotropicSolidMaterialVo;
import com.comac.ins.isfd.service.IIsfdAcousticsIsotropicSolidMaterialService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * 声学固体材料
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/acousticsIsotropicSolidMaterial")
public class IsfdAcousticsIsotropicSolidMaterialController extends BaseController {

    @Autowired
    private IIsfdAcousticsIsotropicSolidMaterialService isfdAcousticsIsotropicSolidMaterialService;

    /**
     * 查询声学固体材料列表
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdAcousticsIsotropicSolidMaterialVo> list(@RequestBody IsfdAcousticsIsotropicSolidMaterialQueryBo queryBo) {
        return isfdAcousticsIsotropicSolidMaterialService.queryPageList(queryBo);
    }

    /**
     * 获取声学固体材料详细信息
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:query")
    @GetMapping("/{id}")
    public R<IsfdAcousticsIsotropicSolidMaterialVo> getInfo(@NotNull(message = "主键不能为空")
                                                            @PathVariable Long id) {
        return R.ok(isfdAcousticsIsotropicSolidMaterialService.queryById(id));
    }


    /**
     * 删除声学固体材料
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:remove")
    @Log(title = "声学固体材料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdAcousticsIsotropicSolidMaterialService.deleteWithValidByIds(List.of(ids)));
    }

    /**
     * 批量上传材料文件
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:add")
    @Log(title = "声学固体材料", businessType = BusinessType.IMPORT)
    @PostMapping("/batchUpload")
    public R<Void> batchUpload(@RequestParam("files") MultipartFile[] files) {
        return isfdAcousticsIsotropicSolidMaterialService.batchUploadMaterials(files);
    }

    /**
     * 编辑材料信息
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:edit")
    @Log(title = "声学固体材料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdAcousticsIsotropicSolidMaterialBo bo) {
        return toAjax(isfdAcousticsIsotropicSolidMaterialService.updateMaterial(bo));
    }

    /**
     * 新增材料信息
     */
    @SaCheckPermission("isfd:acousticsIsotropicSolidMaterial:add")
    @Log(title = "声学固体材料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdAcousticsIsotropicSolidMaterialBo bo) {
        return toAjax(isfdAcousticsIsotropicSolidMaterialService.addMaterial(bo));
    }
}
